console.log("院士页面")
var academyMap = {
	1:"中国科学院",
	2:"中国工程院",
	3:"国际欧亚科学院中国科学中心",
	4:"发展中国家科学院",
	99:"其它"
};


layui.use(['form', 'code', 'laydate','upload','layer','laytpl','element', 'laypage'], function() {
	var laydate = layui.laydate;
	form = layui.form;
	upload = layui.upload;
	layer = layui.layer;
	laytpl = layui.laytpl;
	element = layui.element;

	laypage = layui.laypage;


	layui.code();
	//初始化列表

	$(".searchBtn").click(function () {
		search();
		return false;
	});

	search();

	function setParam(param) {
		var searchName = $(".searchName").val();
		if(searchName){
			param.searchName = searchName;
		}
	}

	function search() {
		$(".academistList").html("");
		var param = {pageNum: 1, pageSize: 5};
		setParam(param);

		AJAX.post(cgiMain.academistAcademistList,
			param,
			function (res) {

				if (res.code == '0000') {
					$(".academistList").data("academistList", res.result.list);
					var tpl = $("#academistTpl").html();
					var resultPage = res.result;
					for (var i = 0; i < resultPage.list.length; i++) {
						var item = resultPage.list[i];
						item.academyName = academyMap[item.academy];
						if(item.academy == 99){
							item.academyName = item.otherAcademy;
						}
						laytpl(tpl).render(item, function (html) {
							$(".academistList").append(html);

							$(".academistList").on("mousemove", '.descTd', function (elem) {
								$(elem.target).removeClass("td_cust");
							});
							$(".academistList").on("mouseout", '.descTr', function (elem) {
								$(elem.target).addClass("td_cust");
							});
						});
					}
					//执行一个laypage实例
					laypage.render({
						elem: 'pagination'
						, limit: 5
						, count: resultPage.totalCount
						, limits: [5]
						, theme: '#1E9FFF'
						, layout: ['prev', 'page', 'next', 'limit', 'count']
						, jump: function (obj, first) {
							if (first == true) {
								return;
							}
							$(".academistList").html("");
							nextPage(obj.curr, 5);

						}
					});
					element.render(".academistList");
					form.render();
				}else{
					$("#pagination").html("");
				}

			});
	}
	function nextPage(pageNum, pageSize) {
		var param = {pageNum: pageNum, pageSize: pageSize};
		setParam(param);
		AJAX.post(cgiMain.academistAcademistList,
			param,
			function (res) {

				if (res.code == '0000') {
					$(".academistList").data("academistList", res.result.list);
					var tpl = $("#academistTpl").html();
					var resultPage = res.result;
					for (var i = 0; i < resultPage.list.length; i++) {
						var item = resultPage.list[i];
						item.academyName = academyMap[item.academy];
						if(item.academy == 99){
							item.academyName = item.otherAcademy;
						}
						laytpl(tpl).render(item, function (html) {
							$(".academistList").append(html);

							$(".academistList").on("mousemove", '.descTd', function (elem) {
								$(elem.target).removeClass("td_cust");
							});
							$(".academistList").on("mouseout", '.descTr', function (elem) {
								$(elem.target).addClass("td_cust");
							});
						});
					}

					element.render(".academistList");
					form.render();
				}

			});
	}

	// 添加工作经验
	$(".add_btn").on("click", function() {
		$("#myModal").show();
		$("#myModal input, #myModal textarea").val("");
	});

	$("#submitNewSubject").click(function () {
		// 判断必填项--提示--统校验
		var params = {};

		// 集合所有参数
		$("#addNewSubjectForm .save_val").each(function() {
			var name = $(this).attr("name");
			var val = $(this).val();
			params[name] = val;
		});

		var url = cgiMain.academistSubjectAdd;
		if(params.id && params.id > 0){
			url = cgiMain.academistSubjectEdit;
		}


		AJAX.post(url,
			params,
			function (res) {
				if(res.code=='0000'){
					layer.msg('保存成功');
					$("#myModal").hide();
					window.location.reload();
				}
			});
	});

});
